package com.gxa.logistics.controller;


import com.gxa.logistics.common.base.PageWrapperDTO;
import com.gxa.logistics.common.base.RespResult;
import com.gxa.logistics.domain.dto.*;
import com.gxa.logistics.domain.vo.CableVO;
import com.gxa.logistics.domain.vo.InsuranceVO;
import com.gxa.logistics.domain.vo.SpareVO;
import com.gxa.logistics.service.InsuranceService;
import com.gxa.logistics.service.SpareService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "计划管理—旧品列表")
@RestController
@RequestMapping("/spare_parts")
@Slf4j
public class SpareController {
    @Autowired
    private SpareService spareService;
    /**
     * 获取用户列表
     */
    @ApiOperation(value = "获取计划列表-分页", notes = "获取计划列表-分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "当前页码数", defaultValue = "1", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", defaultValue = "10", paramType = "query", dataType = "String")
    })
    @GetMapping("/list")
    public RespResult<PageWrapperDTO<SpareVO>> list(SpareReqListDTO spareReqListDTO) {
        return  spareService.list(spareReqListDTO);
    }
    @ApiOperation(value = "合并派单", notes = "合并派单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "item_num", value = "项目编号", required = true, dataType = "Int", paramType = "path"),
    })
    @PostMapping("/update1/{item_num}")
    public RespResult update1(@PathVariable Integer item_num){
        spareService.updateSpare2(item_num);
        return RespResult.success();
    }
    @ApiOperation(value = "合并完单", notes = "合并完单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "item_num", value = "项目编号", required = true, dataType = "Int", paramType = "path"),
    })
    @PostMapping("/update2/{item_num}")
    public RespResult update2(@PathVariable Integer item_num){
        spareService.updateSpare2(item_num);
        return RespResult.success();
    }
    @ApiOperation(value = "获取派单列表-分页", notes = "获取派单列表-分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "当前页码数", defaultValue = "1", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", defaultValue = "10", paramType = "query", dataType = "String")
    })
    @GetMapping("/list1")
    public RespResult<PageWrapperDTO<SpareVO>> list(SpareoReqListDTO spareoReqListDTO) {
        return  spareService.list(spareoReqListDTO);
    }

    @ApiOperation(value = "获取完单列表-分页", notes = "获取完单列表-分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "当前页码数", defaultValue = "1", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", defaultValue = "10", paramType = "query", dataType = "String")
    })
    @GetMapping("/list2")
    public RespResult<PageWrapperDTO<SpareVO>> list(SparetReqListDTO sparetReqListDTO) {
        return  spareService.list(sparetReqListDTO);
    }

    /**
     * 新增车辆
     */
    @ApiOperation(value = "新增保存", notes = "新增保存")
    @PostMapping("/save")
    public RespResult save(@RequestBody @ApiParam(name = "data", value = "计划添加实体") @Validated SpareSaveDTO spareSaveDTO) {
        // 保存
        spareService.insertSpare(spareSaveDTO);
        return RespResult.success();
    }

    /**
     * 修改车辆信息
     */
    @ApiOperation(value = "修改计划", notes = "修改计划")
    @PostMapping("/update")
    public RespResult update(@RequestBody @ApiParam(name = "data", value = "计划修改") SpareUpdateDTO spareUpdateDTO) {
        spareService.updateSpare(spareUpdateDTO);
        return RespResult.success();
    }


    /**
     * 删除用户
     */
    /**
     * 删除用户
     */
    @ApiOperation(value = "删除计划", notes = "删除计划")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "item_name", value = "项目名称", required = true, dataType = "String", paramType = "path"),
    })
    @PostMapping("/delete/{item_name}")
    public RespResult delete(@PathVariable String item_name) {
        spareService.deleteSpareByitemName(item_name);
        return RespResult.success();
    }
}
